Skip to content

fix: Enterprise WeChat docking sub application cannot output thinking process#2489

Merged
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_chat_answer_list
Mar 4, 2025
Merged

fix: Enterprise WeChat docking sub application cannot output thinking process#2489
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_chat_answer_list

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: Enterprise WeChat docking sub application cannot output thinking process

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 4, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

zip(answer_list, range(len(answer_list)))}
_write_context(node_variable, workflow_variable, node, workflow, answer, reasoning_content)


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the identified issues and potential improvements:

Issues:

  1. Variable Access:

    • The line node_variable['application_node_dict'] is accessing a variable named response, which does not exist at that stage of the function execution. This will likely raise an error.
  2. Answer List Handling:

    • The line ${{answer.get('real_node_id') contains interpolation syntax, but it's missing the opening brace {.
    • The logic to update node_variable['application_node_dict'] seems incorrect because both keys ("real_node_id" and "index") should be included in each entry.
  3. Function Parameters:

    • The last parameter passed to _write_context() is workflow, but there is no such parameter defined in the original code snippet you provided.

Potential Improvements:

  1. Correct Variable Name:

    • Ensure that the response variable is correctly referenced if needed or removed if unnecessary.
  2. Fix Template Syntax:

    • Replace ${{answer.get('real_node_id')}} with simply answer.get('real_node_id').
  3. Re-evaluate Data Structure:

    • Review what data structure is intended for node_variable['application_node_dict']. If you mean to store different types of data under 'actual_node_id', adjust the dictionary accordingly.
  4. Parameter Correctness:

    • Double-check that all parameters passed to _write_context() match those expected, and add any necessary parameters that might have been omitted from the previous version.
  5. Error Handling:

    • Consider adding error handling to manage cases where certain fields like 'prompt_tokens', 'content', ..., ' might not always be available in the response.

Without additional context on how these variables interact, some further refinement may be required.

answer_list=other_params.get('answer_list', ""),
message=ChatCompletionMessage(role='assistant', content=content))],
created=datetime.datetime.now().second, model='', object='chat.completion',
usage=CompletionUsage(completion_tokens=completion_tokens,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet seems mostly correct, but there are a few minor adjustments and clarifications that can be made to ensure it works as intended:

  1. Use of get method correctly: In Python dictionaries, using the get() method with a default parameter (other_params.get('reasoning_content', "")) will handle cases where 'reasoning_content' is not present in other_params. This prevents a potential KeyError.

  2. Correct import statement for datetime module: Ensure you have imported the datetime module at the beginning of your file if it's not already imported. The current line imports from both pandas and pyarrow, so I assume datetime is used elsewhere; however, here we just need to make sure it's available.

  3. Consistency in handling None values: When accessing dictionary keys, always check for their existence before proceeding to access them to avoid NoneType errors.

Here’s the code with these points addressed:

import datetime

def to_block_response(self, chat_id, chat_record_id, content, is_end, completion_tokens, other_params):
    # Using get() to safely retrieve reasoning_content from other_params
    reasoning_content = other_params.get('reasoning_content', "")
    
    # Similarly, use get() to safely retrieve answer_list from other_params
    answer_list = other_params.get('answer_list', [])
    
    data = ChatCompletion(
        id=chat_record_id,
        choices=[
            BlockChoice(
                finish_reason='stop',
                index=0,
                chat_id=chat_id,
                reasoning_content=reasoning_content,
-                         answer_list answer_list,
                 message=ChatCompletionMessage(role='assistant', content=content)
            )
        ],
        created=datetime.datetime.now().timestamp(),
        model='',
        object='chat.completion',
        usage=CompletionUsage(completion_tokens=completion_tokens)
    )

# Example usage with an empty list for completeness
example_other_params = {}
to_block_response("id_123", "record_1", "Hello!", True, 20, example_other_params)

This should prevent any runtime errors related to missing keys in the other_params dictionary and maintain proper consistency in value fetching.

@shaohuzhang1 shaohuzhang1 merged commit e420a01 into main Mar 4, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_chat_answer_list branch March 4, 2025 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant